package com.youyi.yychosesdk.utils.result;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import com.youyi.yychosesdk.EasyPhotos;
import com.youyi.yychosesdk.callback.SelectCallback;
import com.youyi.yychosesdk.ui.EasyPhotosActivity;

public class HolderFragment extends Fragment {
    private static final int HOLDER_SELECT_REQUEST_CODE = 68;
    private SelectCallback mSelectCallback;

    @Override // android.support.v4.app.Fragment
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setRetainInstance(true);
    }

    public void startEasyPhoto(SelectCallback selectCallback) {
        this.mSelectCallback = selectCallback;
        EasyPhotosActivity.start(this, 68);
    }

    @Override // android.support.v4.app.Fragment
    public void onActivityResult(int i, int i2, Intent intent) {
        SelectCallback selectCallback;
        super.onActivityResult(i, i2, intent);
        if (-1 == i2) {
            if (i == 68 && this.mSelectCallback != null) {
                this.mSelectCallback.onResult(intent.getParcelableArrayListExtra(EasyPhotos.RESULT_PHOTOS), intent.getBooleanExtra(EasyPhotos.RESULT_SELECTED_ORIGINAL, false));
            }
        } else if (i2 == 0 && i == 68 && (selectCallback = this.mSelectCallback) != null) {
            selectCallback.onCancel();
        }
    }
}
